package com.small.xx.ai.spring;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Swagger配置类
 */
@Configuration
@ConditionalOnClass(name = "org.springframework.web.servlet.HandlerMapping")
@Import(Swagger2Properties.class)
public class Swagger2Configuration implements WebMvcConfigurer {

    @Bean
    @ConditionalOnMissingBean
    public OpenAPI openAPI(Swagger2Properties swagger2Properties) {
        return new OpenAPI()
                .info(new Info()
                        .title(swagger2Properties.getTitle())
                        .version(swagger2Properties.getVersion())
                        .description(swagger2Properties.getDescription())
                        .termsOfService(swagger2Properties.getTermsOfServiceUrl())
                        .license(new License()
                                .name(swagger2Properties.getLicense())
                                .url(swagger2Properties.getLicenseUrl())
                        )
                );
    }
}
